package sistemataller;

import core.*;
import java.sql.*;
import java.awt.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Oscar Aguilera
 */
public class Fichas extends javax.swing.JInternalFrame {
 int fila = -1;
    private String condiciones, tbls;
    private Object[][] result;
    private Query cmd;
    private Conexion conn;
    String tablamaster = "tbl_fichaAuto";
    String[] campos = {"id_fichaAuto", "patente", "rut_cliente", "id_usuario", "comentarios"};
    String[] titcols = {"id", "patente", "rut_cliente", "nombres", "apellidos", "comentarios"};
    String nomkey = "id_fichaAuto";
    DefaultTableModel datos;
    String idmarca = null;
    String idmodelo = null;
    String idUsuario = null;
    /** Creates new form Fichas */
    public Fichas() {
        initComponents();
        System.out.println("iniciando");
        llenaTabla();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblRegistros = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        tblRegistros.setFont(new java.awt.Font("Lucida Grande", 0, 14));
        tblRegistros.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblRegistros.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblRegistrosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblRegistros);

        jButton1.setText("Todos");

        jButton2.setText("Pendientes");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Terminadas");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(294, Short.MAX_VALUE)
                .add(jButton1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton2)
                .add(8, 8, 8))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 626, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jButton2)
                    .add(jButton3))
                .add(3, 3, 3)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 446, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblRegistrosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblRegistrosMouseClicked

        String marca = null;
        String modelo = null;

        conn = new Conexion();
        cmd = new Query(conn);

        String[] campo = {"t1.id_fichaAuto", "t1.patente", "t1.comentarios", "t1.rut_cliente", "t3.nombres", "t3.apellidos", "t3.fono", "t4.nombre", "t5.nombre"};

        tbls = "tbl_fichaAuto t1, tbl_auto t2, tbl_cliente t3, tbl_modelo t4, tbl_marca t5";


        // return result[0][0].toString() + " ::: " + result[0][1].toString();

        fila = tblRegistros.rowAtPoint(evt.getPoint());
        if (fila > -1) {

            String idficha=String.valueOf(datos.getValueAt(fila, 0)) ;

            

        }

      





        conn.desconectar();
}//GEN-LAST:event_tblRegistrosMouseClicked
 private void llenaTabla() {


        conn = new Conexion();
        cmd = new Query(conn);

        condiciones = " t1.patente=t2.patente and  t1.rut_cliente=t3.rut_cliente";
        String[] columna = {"t1.id_fichaAuto", "t2.patente", "t3.rut_cliente", "t3.nombres", "t3.apellidos", "t1.comentarios"};
        String tabla = tablamaster + " t1, tbl_auto t2, tbl_cliente t3";

        result = cmd.leeRegistros(columna, condiciones, tabla);
        datos = new DefaultTableModel(result, titcols);
        tblRegistros.setModel(datos);
        conn.desconectar();
    }
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblRegistros;
    // End of variables declaration//GEN-END:variables

}
